<template>
	<view>
		<post-list :list="post_list"></post-list>
		<u-loadmore v-if="post_list.length > 0" :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" style="padding-bottom: 20upx;" />
		<u-empty mode="data" v-else></u-empty>
	</view>
</template>

<script>
export default {
	data() {
		return {
			type: 0,
			login_user_id: '', //登录用户id
			post_list: [],
			formData: {
				limit: 10,  //每页10条数据
				page: 1,   //第几页
			},
			status: 'loadmore',
			loadingText: '努力加载中',
			loadmoreText: '轻轻上拉',
			nomoreText: '已经到底了哈',
		}
	},
	onLoad(options) {
		this.type = options.type;
		this.login_user_id = uni.getStorageSync('userid');
		//未登录跳转到登录页面
		if (this.login_user_id == '') {
			uni.navigateTo({
				url: '/pages/login/login'
			})
			return false;
		}
		if (this.type == 0) {
			this.get_collection_records();
		}else{
			this.browse_history();
		}
	},
	onReachBottom() {
		if (this.type == 0) {
			this.get_collection_records();
		}else{
			this.browse_history();
		}
		this.status = 'loading';
	},
	methods: {
		async get_collection_records() {
			let get_collection_records = await this.$api.get_collection_records(this.formData);
			if (get_collection_records.code == 1) {
				if (this.formData.page > get_collection_records.data.pagecount) {
					this.status = 'nomore';
				} else {
					this.formData.page++;
					this.status = 'loadmore';
					this.post_list = this.post_list.concat(get_collection_records.data.list);
				}
			}
		},
		async browse_history() {
			let browse_history = await this.$api.browse_history(this.formData);
			if (browse_history.code == 1) {
				if (this.formData.page > browse_history.data.pagecount) {
					this.status = 'nomore';
				} else {
					this.formData.page++;
					this.status = 'loadmore';
					this.post_list = this.post_list.concat(browse_history.data.list);
				}
			}
		}
	}
}
</script>

<style></style>
